package com.zhaoxi.project.wms.controller;

import com.zhaoxi.common.utils.poi.ExcelUtil;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.framework.web.page.TableDataInfo;
import com.zhaoxi.project.wms.domain.MesTaskProcess;
import com.zhaoxi.project.wms.service.impl.MesTaskProcessServiceImpl;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 生产任务产品工序Controller
 *
 * @author zhaoxi
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/mes/taskProcess")
public class MesTaskProcessController extends BaseService {
  @Autowired
  private MesTaskProcessServiceImpl mesTaskProcessService;

  /**
   * 查询生产任务产品工序列表
   */
  @PreAuthorize("@ss.hasPermi('wms:taskProcess:list')")
  @GetMapping("/list")
  public TableDataInfo list(MesTaskProcess mesTaskProcess) {
    startPage();
    List<MesTaskProcess> list = mesTaskProcessService.selectMesTaskProcessList(mesTaskProcess);
    return getDataTable(list);
  }

  /**
   * 导出生产任务产品工序列表
   */
  @PreAuthorize("@ss.hasPermi('wms:taskProcess:export')")
  @Log(title = "生产任务产品工序", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, MesTaskProcess mesTaskProcess) {
    List<MesTaskProcess> list = mesTaskProcessService.selectMesTaskProcessList(mesTaskProcess);
    ExcelUtil<MesTaskProcess> util = new ExcelUtil<MesTaskProcess>(MesTaskProcess.class);
    util.exportExcel(response, list, "生产任务产品工序数据");
  }

  /**
   * 获取生产任务产品工序详细信息
   */
  @PreAuthorize("@ss.hasPermi('wms:taskProcess:query')")
  @GetMapping(value = "/{taskId}")
  public PageData getInfo(@PathVariable("taskId") Long taskId) {
    return success(mesTaskProcessService.selectMesTaskProcessByTaskId(taskId));
  }

  /**
   * 新增生产任务产品工序
   */
  @PreAuthorize("@ss.hasPermi('wms:taskProcess:add')")
  @Log(title = "生产任务产品工序", businessType = BusinessType.INSERT)
  @PostMapping
  public PageData add(@RequestBody MesTaskProcess mesTaskProcess) {
    return toAjax(mesTaskProcessService.insertMesTaskProcess(mesTaskProcess));
  }

  /**
   * 修改生产任务产品工序
   */
  @PreAuthorize("@ss.hasPermi('wms:taskProcess:edit')")
  @Log(title = "生产任务产品工序", businessType = BusinessType.UPDATE)
  @PutMapping
  public PageData edit(@RequestBody MesTaskProcess mesTaskProcess) {
    return toAjax(mesTaskProcessService.updateMesTaskProcess(mesTaskProcess));
  }

  /**
   * 删除生产任务产品工序
   */
  @PreAuthorize("@ss.hasPermi('wms:taskProcess:remove')")
  @Log(title = "生产任务产品工序", businessType = BusinessType.DELETE)
  @DeleteMapping("/{taskIds}")
  public PageData remove(@PathVariable Long[] taskIds) {
    return toAjax(mesTaskProcessService.deleteMesTaskProcessByTaskIds(taskIds));
  }
}
